package iss.java;
import iss.java.list.Node;


import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReadWriteLock;
/**
 * Created by wenke on 2016/9/16.
 */

public class Main_A {
    public static void main(String[] args)throws InterruptedException  {
        Node node=new Node();
        node.setData(50);
        ReadWriteLock rwlock=new ReentrantReadWriteLock();
        Thread thread1=new Thread(){
            public void run() {
                for (int i = 0; i < 100000; i++) {
                    rwlock.writeLock().lock();
                    try {
                        node.setData(node.getData() + 10);
                    }
                    finally {
                        rwlock.writeLock().unlock();
                         }
                    }
                }
        };
        Thread thread2=new Thread(){
            public void run(){
                for(int i=0;i<100000;i++){
                    rwlock.writeLock().lock();
                    try {
                        node.setData(node.getData() - 10);
                    }
                    finally{
                        rwlock.writeLock().unlock();
                    }
                }
            }
        };
        thread1.start();
        thread2.start();
        Thread.sleep(10000);
        System.out.println("运算结果为"+node.getData());
        // TODO: Implement a multithreaded test case against requirement A.
    }
}
